<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <title>Title</title>
    <script src="js/jquery-1.8.3.js" type="text/javascript"></script>
</head>
<body>
<table>
    <thead>
    <td>ID</td>
    <td>NAME</td>
    <td>PWD</td>
    </thead>
    <tbody id="t1"></tbody>
</table>

<button type="button" id="addUser">添加用户</button>
<div id="d" style="display: none">
    用户名:<input type="text" name="uname" id="uname"/><br>
    密码:<input type="password" name="upwd" id="upwd"><br>
    <input type="button" id="add" value="提交">
</div>
</body>
<script>
    $(function () {
        userList();
    });

    function userList() {
        $.ajax({
            url: "UserAction_list",
            type: "POST",
            dataType: "json",
            success: function (data) {
                $("#t1").html("");
                var str = "";
                $(data).each(function (i, n) {
                    str += "<tr>" +
                        "<td>" + n.uid + "</td>" +
                        "<td>" + n.uname + "</td>" +
                        "<td>" + n.upwd + "</td>" +
                        "<td><button class='del' name='del' href='#' onclick='del(" + n.uid + ",this)'>删除</button></td>" +
                        "</tr>";
                });
                $("#t1").append(str);
            }
        })
    };

    $("#add").click(function () {
        $.ajax({
            url: "UserAction_add",
            type: "POST",
            data: {"uname": $("#uname").val(), "upwd": $("#upwd").val()},
            dataType: "json",
            success: function (data) {
                $("#t1").append(str);
            }
        })
    });

    $("#addUser").click(function () {
        $("#d").css("display", "block");
    });

    function del(uid, obj) {
        $.ajax({
            url: "UserAction_del",
            type: "POST",
            data: {uid: uid},
            success: function (data) {
                $(obj).parent().parent().remove();
            }
        })
    }
</script>
</html>